package com.sp.scmdb.action;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sp.scmdb.bean.AreaBean;
import com.sp.scmdb.common.CommonParamter;
import com.sp.scmdb.common.action.BaseAction;
import com.sp.scmdb.webservice.service.UploadAreaService;

@Controller("uploadAreaAction")
@Scope("prototype")
public class UploadAreaAction extends BaseAction<AreaBean> {

	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(UploadAreaAction.class);
	private UploadAreaService areaService;

	@Autowired
	public void setAreaService(UploadAreaService areaService) {
		this.areaService = areaService;
	}

	@SuppressWarnings("unchecked")
	public String findAll() {
		try {
			AreaBean areaBean = null;
			if (StringUtils.isNotEmpty(pageName)) {
				areaBean = (AreaBean) session.get("areaBean");
			}else{
				entity.setPageNo(1);
			}
			setEntity(areaService.queryAll(entity, areaBean));
			session.put("areaBean", entity);
			session.put("areaListType", CommonParamter.TypeCommon.getAreaType());
			return SUCCESS;
		} catch (Exception e) {
			log.error("findAll failed! reason:" + e.getMessage());
			return "fail";
		}
	}
	
	public String uploadArea(){
		String result = areaService.uploadArea();

		messageSession("0", result);
		
		return "upload";
	}
}
